﻿@COFE ?= {}

$ = jQuery
Signin = COFE.Signin
utils = COFE.utils


class Options extends Spine.Controller
  constructor : ->
    super  

  elements : 
    ".signout" : "btnSignout"

  events :   
    "click .home" : "home"     
    "click .hierarchy" : "hierarchy"      
    "click .signout" : "signout"
    "click .search" : "search"
     
  init : ->
  

  home : =>    
    @el.dialog('close')
    @App.changePath("", "Options")      

  search : =>    
    @el.dialog('close')
    # Open the search dialog after option dialog closed.
    setTimeout("$.mobile.changePage('#search')", 350);  

  hierarchy : =>    
    @el.dialog('close')
    # Open the hierarchy dialog after option dialog closed.
    setTimeout("$.mobile.changePage('#hierarchy')", 350);  

  signout : =>
    @el.dialog('close')
    setTimeout("$.mobile.changePage('#signin')", 350);          

    #clear cache
    COFE.Entry.destroyAll()
    COFE.EntryList.destroyAll()
    
    utils.signout(
      () => utils.showMessage("Signout", "Signout"),
      (error) => utils.showMessage(error, "Signout")
    )

COFE.Options = Options

